<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="author" content="Ko Chiu Yu" />

<meta name="date" content="2019-04-19" />

<title>Candle Stick Pattern Recognition</title>



<style type="text/css">code{white-space: pre;}</style>
<style type="text/css" data-origin="pandoc">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */

</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
  var sheets = document.styleSheets;
  for (var i = 0; i < sheets.length; i++) {
    if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
    try { var rules = sheets[i].cssRules; } catch (e) { continue; }
    for (var j = 0; j < rules.length; j++) {
      var rule = rules[j];
      // check if there is a div.sourceCode rule
      if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
      var style = rule.style.cssText;
      // check if color or background-color is set
      if (rule.style.color === '' || rule.style.backgroundColor === '') continue;
      // replace div.sourceCode by a pre.sourceCode rule
      sheets[i].deleteRule(j);
      sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
    }
  }
})();
</script>



<link href="data:text/css;charset=utf-8,body%20%7B%0Abackground%2Dcolor%3A%20%23fff%3B%0Amargin%3A%201em%20auto%3B%0Amax%2Dwidth%3A%20700px%3B%0Aoverflow%3A%20visible%3B%0Apadding%2Dleft%3A%202em%3B%0Apadding%2Dright%3A%202em%3B%0Afont%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0Afont%2Dsize%3A%2014px%3B%0Aline%2Dheight%3A%201%2E35%3B%0A%7D%0A%23header%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0A%23TOC%20%7B%0Aclear%3A%20both%3B%0Amargin%3A%200%200%2010px%2010px%3B%0Apadding%3A%204px%3B%0Awidth%3A%20400px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Aborder%2Dradius%3A%205px%3B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Afont%2Dsize%3A%2013px%3B%0Aline%2Dheight%3A%201%2E3%3B%0A%7D%0A%23TOC%20%2Etoctitle%20%7B%0Afont%2Dweight%3A%20bold%3B%0Afont%2Dsize%3A%2015px%3B%0Amargin%2Dleft%3A%205px%3B%0A%7D%0A%23TOC%20ul%20%7B%0Apadding%2Dleft%3A%2040px%3B%0Amargin%2Dleft%3A%20%2D1%2E5em%3B%0Amargin%2Dtop%3A%205px%3B%0Amargin%2Dbottom%3A%205px%3B%0A%7D%0A%23TOC%20ul%20ul%20%7B%0Amargin%2Dleft%3A%20%2D2em%3B%0A%7D%0A%23TOC%20li%20%7B%0Aline%2Dheight%3A%2016px%3B%0A%7D%0Atable%20%7B%0Amargin%3A%201em%20auto%3B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dcolor%3A%20%23DDDDDD%3B%0Aborder%2Dstyle%3A%20outset%3B%0Aborder%2Dcollapse%3A%20collapse%3B%0A%7D%0Atable%20th%20%7B%0Aborder%2Dwidth%3A%202px%3B%0Apadding%3A%205px%3B%0Aborder%2Dstyle%3A%20inset%3B%0A%7D%0Atable%20td%20%7B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dstyle%3A%20inset%3B%0Aline%2Dheight%3A%2018px%3B%0Apadding%3A%205px%205px%3B%0A%7D%0Atable%2C%20table%20th%2C%20table%20td%20%7B%0Aborder%2Dleft%2Dstyle%3A%20none%3B%0Aborder%2Dright%2Dstyle%3A%20none%3B%0A%7D%0Atable%20thead%2C%20table%20tr%2Eeven%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Ap%20%7B%0Amargin%3A%200%2E5em%200%3B%0A%7D%0Ablockquote%20%7B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Apadding%3A%200%2E25em%200%2E75em%3B%0A%7D%0Ahr%20%7B%0Aborder%2Dstyle%3A%20solid%3B%0Aborder%3A%20none%3B%0Aborder%2Dtop%3A%201px%20solid%20%23777%3B%0Amargin%3A%2028px%200%3B%0A%7D%0Adl%20%7B%0Amargin%2Dleft%3A%200%3B%0A%7D%0Adl%20dd%20%7B%0Amargin%2Dbottom%3A%2013px%3B%0Amargin%2Dleft%3A%2013px%3B%0A%7D%0Adl%20dt%20%7B%0Afont%2Dweight%3A%20bold%3B%0A%7D%0Aul%20%7B%0Amargin%2Dtop%3A%200%3B%0A%7D%0Aul%20li%20%7B%0Alist%2Dstyle%3A%20circle%20outside%3B%0A%7D%0Aul%20ul%20%7B%0Amargin%2Dbottom%3A%200%3B%0A%7D%0Apre%2C%20code%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0Aborder%2Dradius%3A%203px%3B%0Acolor%3A%20%23333%3B%0Awhite%2Dspace%3A%20pre%2Dwrap%3B%20%0A%7D%0Apre%20%7B%0Aborder%2Dradius%3A%203px%3B%0Amargin%3A%205px%200px%2010px%200px%3B%0Apadding%3A%2010px%3B%0A%7D%0Apre%3Anot%28%5Bclass%5D%29%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Acode%20%7B%0Afont%2Dfamily%3A%20Consolas%2C%20Monaco%2C%20%27Courier%20New%27%2C%20monospace%3B%0Afont%2Dsize%3A%2085%25%3B%0A%7D%0Ap%20%3E%20code%2C%20li%20%3E%20code%20%7B%0Apadding%3A%202px%200px%3B%0A%7D%0Adiv%2Efigure%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0Aimg%20%7B%0Abackground%2Dcolor%3A%20%23FFFFFF%3B%0Apadding%3A%202px%3B%0Aborder%3A%201px%20solid%20%23DDDDDD%3B%0Aborder%2Dradius%3A%203px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Amargin%3A%200%205px%3B%0A%7D%0Ah1%20%7B%0Amargin%2Dtop%3A%200%3B%0Afont%2Dsize%3A%2035px%3B%0Aline%2Dheight%3A%2040px%3B%0A%7D%0Ah2%20%7B%0Aborder%2Dbottom%3A%204px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Apadding%2Dbottom%3A%202px%3B%0Afont%2Dsize%3A%20145%25%3B%0A%7D%0Ah3%20%7B%0Aborder%2Dbottom%3A%202px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Afont%2Dsize%3A%20120%25%3B%0A%7D%0Ah4%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23f7f7f7%3B%0Amargin%2Dleft%3A%208px%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Ah5%2C%20h6%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23ccc%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Aa%20%7B%0Acolor%3A%20%230033dd%3B%0Atext%2Ddecoration%3A%20none%3B%0A%7D%0Aa%3Ahover%20%7B%0Acolor%3A%20%236666ff%3B%20%7D%0Aa%3Avisited%20%7B%0Acolor%3A%20%23800080%3B%20%7D%0Aa%3Avisited%3Ahover%20%7B%0Acolor%3A%20%23BB00BB%3B%20%7D%0Aa%5Bhref%5E%3D%22http%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0Aa%5Bhref%5E%3D%22https%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0A%0Acode%20%3E%20span%2Ekw%20%7B%20color%3A%20%23555%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Edt%20%7B%20color%3A%20%23902000%3B%20%7D%20%0Acode%20%3E%20span%2Edv%20%7B%20color%3A%20%2340a070%3B%20%7D%20%0Acode%20%3E%20span%2Ebn%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Efl%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Ech%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Est%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Eco%20%7B%20color%3A%20%23888888%3B%20font%2Dstyle%3A%20italic%3B%20%7D%20%0Acode%20%3E%20span%2Eot%20%7B%20color%3A%20%23007020%3B%20%7D%20%0Acode%20%3E%20span%2Eal%20%7B%20color%3A%20%23ff0000%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Efu%20%7B%20color%3A%20%23900%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%20code%20%3E%20span%2Eer%20%7B%20color%3A%20%23a61717%3B%20background%2Dcolor%3A%20%23e3d2d2%3B%20%7D%20%0A" rel="stylesheet" type="text/css" />




</head>

<body>




<h1 class="title toc-ignore">Candle Stick Pattern Recognition</h1>
<h4 class="author">Ko Chiu Yu</h4>
<h4 class="date">2019-04-19</h4>



<p>How can you recongize candle stick patterns? This R package allows you to recognized them based on formulas.</p>
<div id="installation" class="section level2">
<h2>Installation</h2>
<p>To install this package, it is the easist to use devtools:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#install.packages(&quot;devtools&quot;)</span>
<span class="kw">library</span>(devtools)</code></pre></div>
<p>Then we can use the <code>install_github</code> to get the package directly:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#install_github(&quot;kochiuyu/CandleStickPattern&quot;)</span>
<span class="kw">library</span>(CandleStickPattern)</code></pre></div>
<p>To start, let us review the basic of candle stick.</p>
</div>
<div id="candle-stick-basics" class="section level1">
<h1>Candle Stick Basics</h1>
<p>Candle Stick visuall display the OHLC data. OHLC means open (Op), high (Hi), low (Li) and close (Cl) prices.</p>
<p>First, the rectangle body tells close and open prices. The color of the rectangle would tell whether the higher end of body is open or close price:</p>
<ul>
<li>Bullish Candle: close &gt; open (green or white)</li>
<li>Bearish Candle: close &lt; open (red or black)</li>
</ul>
<p>Two ends tells high and low prices. The line between two ends to the candle are called shadow:</p>
<ul>
<li>Upper Shadow: high and real body</li>
<li>Lower Shadow: low and real body</li>
</ul>
</div>
<div id="lengths" class="section level1">
<h1>Lengths</h1>
<p>Size of candle body (rectangle) and the lenght of two shadows are important for the pattern recognition. We first define them first:</p>
<ul>
<li><p>Upper shadow length: <span class="math inline">\(US(t)=Hi(t)-\max\{Op(t),Cl(t)\}\)</span></p></li>
<li><p>Lower shadow length: <span class="math inline">\(LS(t)=\min\{Op(t),Cl(t)\}-Lo(t)\)</span></p></li>
<li><p>Whole candle length: <span class="math inline">\(WC(t)=Hi(t)-Lo(t)\)</span></p></li>
<li><p>Body length: <span class="math inline">\(BL(t)= |Op(t)-Cl(t)|\)</span></p></li>
</ul>
<div id="size-of-body-length" class="section level2">
<h2>Size of body length</h2>
<p>Compare with whole candle length:</p>
<ul>
<li><p>small body: <span class="math inline">\(\delta WC(t) &gt; BL(t)\)</span> for small <span class="math inline">\(\delta=0.1\)</span></p></li>
<li><p>large body: <span class="math inline">\(\delta WC(t) &lt; BL(t)\)</span> for large <span class="math inline">\(\delta=0.9\)</span></p></li>
</ul>
</div>
<div id="size-of-shadow" class="section level2">
<h2>Size of shadow</h2>
<p>Compare with whole candle length:</p>
<ul>
<li><p>short upper shadow: <span class="math inline">\(\delta WC(t) &gt; US(t)\)</span> for small <span class="math inline">\(\delta=0.1\)</span></p></li>
<li><p>long upper shadow: <span class="math inline">\(\delta WC(t) &lt; US(t)\)</span> for large <span class="math inline">\(\delta=0.9\)</span></p></li>
</ul>
</div>
<div id="size-of-candle-length" class="section level2">
<h2>Size of candle length</h2>
<p>Compare with historical whole candle lengths:</p>
<ul>
<li><p>small body: <span class="math inline">\(WC(t) &lt; \delta \times median\{WC(t-1),...,WC(t-n-1)\}\)</span> for parameter <span class="math inline">\(\delta=1\)</span></p></li>
<li><p>large body: <span class="math inline">\(WC(t) &gt; \delta \times median\{WC(t-1),...,WC(t-n-1)\}\)</span> for parameter <span class="math inline">\(\delta=1\)</span></p></li>
</ul>
<p>Similar ideas can be extended to body length and shadow sizes.</p>
</div>
<div id="price-movement" class="section level2">
<h2>Price Movement</h2>
<p>Daily</p>
<ul>
<li><p>Up: <span class="math inline">\(U(t)=1 \text{ if } Cl(t)&gt;Op(t)\)</span> and 0 otherwise</p></li>
<li><p>Down: <span class="math inline">\(D(t)=1 \text{ if } Cl(t)&lt;Op(t)\)</span> and 0 otherwise</p></li>
</ul>
<p>Inter-day Gap</p>
<ul>
<li><p>Gap up: candle body Day 2 is higher than that of Day 1. <span class="math display">\[GU(t) =1 \text{ if }  \min\{Op(t),Cl(t)\}&gt;\max\{Op(t-1),Cl(t-1)\}\]</span></p></li>
<li><p>Gap down: candle body Day 2 is lower than that of Day 1. <span class="math display">\[GD(t) =1 \text{ if }  \max\{Op(t),Cl(t)\}&gt;\min\{Op(t-1),Cl(t-1)\}\]</span></p></li>
</ul>
</div>
</div>
<div id="doji-1-day-pattern" class="section level1">
<h1>Doji (1-day pattern)</h1>
<div id="doji-japanese-crux" class="section level2">
<h2>Doji (Japanese: Crux)</h2>
<p>Indecision signal: up and down forces are balanced</p>
<ol style="list-style-type: decimal">
<li>long candle stick (High &gt;&gt; Low)</li>
<li>narrow real body (Close ~ Open)</li>
</ol>
<p>Let see an example:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2011-07-08/2011-07-19'</span>]
<span class="kw">candleChart</span>(price,<span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>doji()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">doji</span>(price)
<span class="co">#&gt;             doji</span>
<span class="co">#&gt; 2011-07-08 FALSE</span>
<span class="co">#&gt; 2011-07-11  TRUE</span>
<span class="co">#&gt; 2011-07-12  TRUE</span>
<span class="co">#&gt; 2011-07-13  TRUE</span>
<span class="co">#&gt; 2011-07-14 FALSE</span>
<span class="co">#&gt; 2011-07-15 FALSE</span>
<span class="co">#&gt; 2011-07-18  TRUE</span>
<span class="co">#&gt; 2011-07-19 FALSE</span></code></pre></div>
</div>
<div id="dragonfly-doji" class="section level2">
<h2>Dragonfly Doji</h2>
<p>Bullish signal: resist downward pressure</p>
<ol style="list-style-type: decimal">
<li>long candle stick + narrow real body (Doji)</li>
<li>short upper shadow (High ~ Close ~ Open)</li>
</ol>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2014-10-28/2014-11-03'</span>]
<span class="kw">candleChart</span>(price,<span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>dragonfly.doji()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">dragonfly.doji</span>(price)
<span class="co">#&gt;            dragonfly doji</span>
<span class="co">#&gt; 2014-10-28          FALSE</span>
<span class="co">#&gt; 2014-10-29          FALSE</span>
<span class="co">#&gt; 2014-10-30          FALSE</span>
<span class="co">#&gt; 2014-10-31           TRUE</span>
<span class="co">#&gt; 2014-11-03          FALSE</span></code></pre></div>
</div>
<div id="gravestone-doji" class="section level2">
<h2>Gravestone Doji</h2>
<p>Bullish signal : resist downward pressure</p>
<ol style="list-style-type: decimal">
<li>Doji (long candle stick + narrow real body)</li>
<li>Low ~ Close ~ Open (short lower shadow)</li>
</ol>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-MSFT[<span class="st">'2015-04-28/2015-05-01'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>graveston.doji()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">gravestone.doji</span>(price)
<span class="co">#&gt;            gravestone.doji</span>
<span class="co">#&gt; 2015-04-28           FALSE</span>
<span class="co">#&gt; 2015-04-29           FALSE</span>
<span class="co">#&gt; 2015-04-30            TRUE</span>
<span class="co">#&gt; 2015-05-01           FALSE</span></code></pre></div>
</div>
</div>
<div id="harmers-2-day-pattern" class="section level1">
<h1>Harmers (2-day pattern)</h1>
<div id="harmer-and-hang-man" class="section level2">
<h2>Harmer and Hang Man</h2>
<p>Reversal signal:</p>
<ol style="list-style-type: decimal">
<li>Short upper shadow</li>
<li>Long lower shadow</li>
</ol>
<ul>
<li>Harmer: Bullish signal in a downward trend</li>
<li>Hang Man: Bearish signal in a upward trend</li>
</ul>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2011-10-18/2011-10-25'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>hammer()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">hammer</span>(price)
<span class="co">#&gt;            hammer</span>
<span class="co">#&gt; 2011-10-18  FALSE</span>
<span class="co">#&gt; 2011-10-19  FALSE</span>
<span class="co">#&gt; 2011-10-20  FALSE</span>
<span class="co">#&gt; 2011-10-21   TRUE</span>
<span class="co">#&gt; 2011-10-24  FALSE</span>
<span class="co">#&gt; 2011-10-25  FALSE</span></code></pre></div>
</div>
<div id="inverted-harmer-and-shooting-stars" class="section level2">
<h2>Inverted Harmer and Shooting Stars</h2>
<p>Reversal signal:</p>
<ol style="list-style-type: decimal">
<li>Long upper shadow</li>
<li>Short lower shadow</li>
</ol>
<ul>
<li>Inverted Harmer: Bullish signal in a downward trend</li>
<li>Shooting Stars: Bearish signal in a upward trend</li>
</ul>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2011-11-20/2011-11-30'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>inverted.hammer()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">inverted.hammer</span>(price)
<span class="co">#&gt;            inverted harmer</span>
<span class="co">#&gt; 2011-11-21           FALSE</span>
<span class="co">#&gt; 2011-11-22           FALSE</span>
<span class="co">#&gt; 2011-11-23           FALSE</span>
<span class="co">#&gt; 2011-11-25            TRUE</span>
<span class="co">#&gt; 2011-11-28           FALSE</span>
<span class="co">#&gt; 2011-11-29           FALSE</span>
<span class="co">#&gt; 2011-11-30           FALSE</span></code></pre></div>
</div>
</div>
<div id="engulfing-patterns-2-day-pattern" class="section level1">
<h1>Engulfing Patterns (2-day pattern)</h1>
<div id="bullish-engulfing" class="section level2">
<h2>Bullish Engulfing</h2>
<p>Bullish signal as bullish force dominates:</p>
<ol style="list-style-type: decimal">
<li>Bearish Candle on Day 1</li>
<li>Bullish Candle on Day 2</li>
<li>Real body of Day 1 Candle within that of Day 2.</li>
</ol>
</div>
<div id="example" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2011-11-02/2011-11-08'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>bullish.engulf()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">bullish.engulf</span>(price)
<span class="co">#&gt;            bullish engulfing</span>
<span class="co">#&gt; 2011-11-02             FALSE</span>
<span class="co">#&gt; 2011-11-03             FALSE</span>
<span class="co">#&gt; 2011-11-04             FALSE</span>
<span class="co">#&gt; 2011-11-07              TRUE</span>
<span class="co">#&gt; 2011-11-08             FALSE</span></code></pre></div>
</div>
<div id="bearish-enguling" class="section level2">
<h2>Bearish Enguling</h2>
<p>Bearish signal as bearish force dominates:</p>
<ol style="list-style-type: decimal">
<li>Bullish Candle on Day 1</li>
<li>Bearish Candle on Day 2</li>
<li>Real body of Day 1 Candle within that of Day 2.</li>
</ol>
</div>
<div id="example-1" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-MSFT[<span class="st">'2011-12-15/2011-12-20'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>bearish.engulf()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">bearish.engulf</span>(price)
<span class="co">#&gt;            bearish engulfing</span>
<span class="co">#&gt; 2011-12-15                NA</span>
<span class="co">#&gt; 2011-12-16             FALSE</span>
<span class="co">#&gt; 2011-12-19              TRUE</span>
<span class="co">#&gt; 2011-12-20             FALSE</span></code></pre></div>
</div>
</div>
<div id="harami-pregnant2-day-pattern" class="section level1">
<h1>Harami (Pregnant:2-day pattern)</h1>
<div id="bullish-harami" class="section level2">
<h2>Bullish Harami</h2>
<p>Bullish signal as bullish force fights back:</p>
<ol style="list-style-type: decimal">
<li>Large Bearish Candle on Day 1</li>
<li>Small Bullish Candle on Day 2</li>
<li>Real body of Day 2 Candle within that of Day 1.</li>
</ol>
</div>
<div id="example-2" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2011-12-27/2011-12-30'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>bullish.harami()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">bullish.harami</span>(price)
<span class="co">#&gt;            bullish harami</span>
<span class="co">#&gt; 2011-12-27             NA</span>
<span class="co">#&gt; 2011-12-28          FALSE</span>
<span class="co">#&gt; 2011-12-29           TRUE</span>
<span class="co">#&gt; 2011-12-30          FALSE</span></code></pre></div>
</div>
<div id="bearish-harami" class="section level2">
<h2>Bearish Harami</h2>
<p>Bearish signal as bearish force fights back</p>
<ol style="list-style-type: decimal">
<li>Large Bullish Candle on Day 1</li>
<li>Small Bearish Candle on Day 2</li>
<li>Real body of Day 2 Candle within that of Day 1.</li>
</ol>
</div>
<div id="example-3" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2011-11-02/2011-11-07'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>bearish.harami()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">bearish.harami</span>(price)
<span class="co">#&gt;            bearish harami</span>
<span class="co">#&gt; 2011-11-02             NA</span>
<span class="co">#&gt; 2011-11-03          FALSE</span>
<span class="co">#&gt; 2011-11-04           TRUE</span>
<span class="co">#&gt; 2011-11-07          FALSE</span></code></pre></div>
</div>
</div>
<div id="median-reversal-2-day-pattern" class="section level1">
<h1>Median Reversal (2-day pattern)</h1>
<div id="piercing-line" class="section level2">
<h2>Piercing Line</h2>
<p>Bullish signal</p>
<ol style="list-style-type: decimal">
<li>Bearish candle on day 1</li>
<li>Bullish candle on day 2</li>
<li>Close on day 2 &gt; mid point of day 1 body</li>
</ol>
</div>
<div id="example-4" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-MSFT[<span class="st">'2011-07-26/2011-07-30'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>piercing.line()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">piercing.line</span>(price)
<span class="co">#&gt;            piercing line</span>
<span class="co">#&gt; 2011-07-26            NA</span>
<span class="co">#&gt; 2011-07-27         FALSE</span>
<span class="co">#&gt; 2011-07-28          TRUE</span>
<span class="co">#&gt; 2011-07-29         FALSE</span></code></pre></div>
</div>
<div id="dark-cloud-cover" class="section level2">
<h2>Dark cloud cover</h2>
<p>Bullish signal</p>
<ol style="list-style-type: decimal">
<li>Bullish candle on day 1</li>
<li>Bearish candle on day 2</li>
<li>Close on day 2 &lt; mid point of day 1 body</li>
</ol>
</div>
<div id="example-5" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2011-09-16/2011-09-21'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>dark.cloud.cover()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">dark.cloud.cover</span>(price)
<span class="co">#&gt;            dark cloud cover</span>
<span class="co">#&gt; 2011-09-16            FALSE</span>
<span class="co">#&gt; 2011-09-19            FALSE</span>
<span class="co">#&gt; 2011-09-20             TRUE</span>
<span class="co">#&gt; 2011-09-21            FALSE</span></code></pre></div>
</div>
</div>
<div id="two-in-a-row" class="section level1">
<h1>Two in a row</h1>
<div id="kicking-up" class="section level2">
<h2>Kicking up</h2>
<p>Bullish signal:</p>
<ol style="list-style-type: decimal">
<li>bearish candle on day 1</li>
<li>bullish candle on day 2</li>
<li>gap up between day 1 and day 2</li>
</ol>
</div>
<div id="example-6" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-MSFT[<span class="st">'2011-11-08/2011-11-14'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>kick.up()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">kick.up</span>(price)
<span class="co">#&gt;            kick up</span>
<span class="co">#&gt; 2011-11-08      NA</span>
<span class="co">#&gt; 2011-11-09   FALSE</span>
<span class="co">#&gt; 2011-11-10   FALSE</span>
<span class="co">#&gt; 2011-11-11    TRUE</span>
<span class="co">#&gt; 2011-11-14   FALSE</span></code></pre></div>
</div>
<div id="kicking-down" class="section level2">
<h2>Kicking Down</h2>
<p>Bearish signal:</p>
<ol style="list-style-type: decimal">
<li>bullish candle on day 1</li>
<li>bearish candle on day 2</li>
<li>gap down between day 1 and day 2</li>
</ol>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2010-08-16/2010-08-19'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>kick.down()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">kick.down</span>(price)
<span class="co">#&gt;            kick down</span>
<span class="co">#&gt; 2010-08-16     FALSE</span>
<span class="co">#&gt; 2010-08-17     FALSE</span>
<span class="co">#&gt; 2010-08-18     FALSE</span>
<span class="co">#&gt; 2010-08-19      TRUE</span></code></pre></div>
</div>
</div>
<div id="three-in-a-row-3-day-pattern" class="section level1">
<h1>Three-in-a-row (3-day pattern)</h1>
<div id="three-white-solders" class="section level2">
<h2>Three white solders</h2>
<p>Bullish signal:</p>
<ol style="list-style-type: decimal">
<li>Large bullish candles for 3 days</li>
<li>Open prices are rising for 3 days</li>
<li>Close prices are rising for 3 days</li>
</ol>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-MSFT[<span class="st">'2007-05-20/2007-06-01'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>three.white.soldiers()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">TWS &lt;-<span class="st"> </span><span class="kw">three.white.soldiers</span>(MSFT)
TWS[<span class="st">'2007-05-20/2007-06-01'</span>]
<span class="co">#&gt;            three white soliders</span>
<span class="co">#&gt; 2007-05-21                FALSE</span>
<span class="co">#&gt; 2007-05-22                FALSE</span>
<span class="co">#&gt; 2007-05-23                FALSE</span>
<span class="co">#&gt; 2007-05-24                FALSE</span>
<span class="co">#&gt; 2007-05-25                FALSE</span>
<span class="co">#&gt; 2007-05-29                FALSE</span>
<span class="co">#&gt; 2007-05-30                 TRUE</span>
<span class="co">#&gt; 2007-05-31                FALSE</span>
<span class="co">#&gt; 2007-06-01                FALSE</span></code></pre></div>
</div>
<div id="three-black-crows" class="section level2">
<h2>Three Black Crows</h2>
<p>Bearish signal:</p>
<ol style="list-style-type: decimal">
<li>Large bearish candles for 3 days</li>
<li>Open prices are dropping for 3 days</li>
<li>Close prices are dropping for 3 days</li>
</ol>
</div>
<div id="example-7" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-MSFT[<span class="st">'2010-01-15/2010-02-09'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>three.black.crows()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">TBC &lt;-<span class="st"> </span><span class="kw">three.black.crows</span>(MSFT)
TBC[<span class="st">'2007-05-20/2007-06-01'</span>]
<span class="co">#&gt;            three black crows</span>
<span class="co">#&gt; 2007-05-21             FALSE</span>
<span class="co">#&gt; 2007-05-22             FALSE</span>
<span class="co">#&gt; 2007-05-23             FALSE</span>
<span class="co">#&gt; 2007-05-24              TRUE</span>
<span class="co">#&gt; 2007-05-25             FALSE</span>
<span class="co">#&gt; 2007-05-29             FALSE</span>
<span class="co">#&gt; 2007-05-30             FALSE</span>
<span class="co">#&gt; 2007-05-31             FALSE</span>
<span class="co">#&gt; 2007-06-01             FALSE</span></code></pre></div>
</div>
</div>
<div id="star-3-day-pattern" class="section level1">
<h1>Star (3-day pattern)</h1>
<div id="morning-star" class="section level2">
<h2>Morning star</h2>
<p>Bullish signal:</p>
<ol style="list-style-type: decimal">
<li>Large bearish candle on day 1</li>
<li>Small candle (or doji) on day 2</li>
<li>Large bullish candle on day 3</li>
<li>Gap down between day 1 and day 2</li>
<li>Gap up between day 2 and day 3</li>
</ol>
</div>
<div id="example-8" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-<span class="st"> </span>MSFT[<span class="st">'2013-06-09/2013-06-18'</span>]
<span class="kw">candleChart</span>(MSFT[<span class="st">'2013-06-09/2013-06-18'</span>], <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>morning.star()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">MS &lt;-<span class="st"> </span><span class="kw">morning.star</span>(MSFT)
MS[<span class="st">'2013-06-09/2013-06-18'</span>]
<span class="co">#&gt;            morning star</span>
<span class="co">#&gt; 2013-06-10        FALSE</span>
<span class="co">#&gt; 2013-06-11        FALSE</span>
<span class="co">#&gt; 2013-06-12        FALSE</span>
<span class="co">#&gt; 2013-06-13        FALSE</span>
<span class="co">#&gt; 2013-06-14        FALSE</span>
<span class="co">#&gt; 2013-06-17         TRUE</span>
<span class="co">#&gt; 2013-06-18        FALSE</span></code></pre></div>
</div>
<div id="evening-star" class="section level2">
<h2>Evening Star</h2>
<p>Bearish Signal:</p>
<ol style="list-style-type: decimal">
<li>Large <strong>bullish</strong> candle on day 1</li>
<li>Small candle (or doji) on day 2</li>
<li>Large <strong>bearish</strong> candle on day 3</li>
<li><strong>Gap up</strong> between day 1 and day 2</li>
<li><strong>Gap down</strong> between day 2 and day 3</li>
</ol>
</div>
<div id="example-9" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-MSFT[<span class="st">'2011-11-01/2011-11-11'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>evening.star()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">ES &lt;-<span class="st"> </span><span class="kw">evening.star</span>(MSFT)
ES[<span class="st">'2011-11-01/2011-11-11'</span>]
<span class="co">#&gt;            evening star</span>
<span class="co">#&gt; 2011-11-01        FALSE</span>
<span class="co">#&gt; 2011-11-02        FALSE</span>
<span class="co">#&gt; 2011-11-03        FALSE</span>
<span class="co">#&gt; 2011-11-04        FALSE</span>
<span class="co">#&gt; 2011-11-07        FALSE</span>
<span class="co">#&gt; 2011-11-08        FALSE</span>
<span class="co">#&gt; 2011-11-09         TRUE</span>
<span class="co">#&gt; 2011-11-10        FALSE</span>
<span class="co">#&gt; 2011-11-11        FALSE</span></code></pre></div>
</div>
</div>
<div id="three-methods-5-day-pattern" class="section level1">
<h1>Three Methods (5-day pattern)</h1>
<div id="rising-three" class="section level2">
<h2>Rising Three</h2>
<p>Bullish signal:</p>
<ol style="list-style-type: decimal">
<li>Large bullish candle on day 1</li>
<li>(small) bearish candles for next 3 days</li>
<li>Large bullish candle on day 5</li>
<li>Day 1 low is lowest</li>
<li>Day 5 high is highest</li>
</ol>
</div>
<div id="example-10" class="section level2">
<h2>Example</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">price &lt;-MSFT[<span class="st">'2012-01-10/2012-01-22'</span>]
<span class="kw">candleChart</span>(price, <span class="dt">theme=</span><span class="st">'white'</span>)</code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now let us see whether our code can recongize it. The synatx is <code>rising.three()</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">RT &lt;-<span class="st"> </span><span class="kw">rising.three</span>(MSFT)
RT[<span class="st">'2012-01-10/2012-01-22'</span>]
<span class="co">#&gt;            rising three</span>
<span class="co">#&gt; 2012-01-10        FALSE</span>
<span class="co">#&gt; 2012-01-11        FALSE</span>
<span class="co">#&gt; 2012-01-12        FALSE</span>
<span class="co">#&gt; 2012-01-13        FALSE</span>
<span class="co">#&gt; 2012-01-17        FALSE</span>
<span class="co">#&gt; 2012-01-18        FALSE</span>
<span class="co">#&gt; 2012-01-19        FALSE</span>
<span class="co">#&gt; 2012-01-20         TRUE</span></code></pre></div>
</div>
<div id="falling-three" class="section level2">
<h2>Falling three</h2>
<p>Bearish signal:</p>
<ol style="list-style-type: decimal">
<li>Large bearish candle on day 1</li>
<li>(small) bullish candles for next 3 days</li>
<li>Large bearish candle on day 5</li>
<li>Day 1 high is the highest</li>
<li>Day 5 low is the lowest</li>
</ol>
<p>The synatx is <code>falling.three()</code>.</p>
</div>
</div>
<div id="appendix-trend" class="section level1">
<h1>Appendix: Trend</h1>
<p>This part is less related to candle stick pattern but nevertheless sometimes candle chart pattern requires the usage of trend. This package provides a very simple way to determine trend using exponential moving average (EMA.)</p>
<p>We compare a short-run EMA with a long-run EMA to determine trend.</p>
<div id="up-trend" class="section level2">
<h2>Up trend</h2>
<p>If the short-run EMA is bigger than long-run EMA, then it is upward trend.</p>
<p>The synatx is <code>up.trend(price, S, L, delta)</code> where <code>S</code> and <code>L</code> are the number of periods for short-run and long-run EMA, and <code>delta</code> is sensitivity parameter.</p>
</div>
<div id="down-trend" class="section level2">
<h2>Down trend</h2>
<p>If the short-run EMA is smaller than long-run EMA, then it is upward trend.</p>
<p>The synatx is <code>down.trend(price, S, L, delta)</code> where <code>S</code> and <code>L</code> are the number of periods for short-run and long-run EMA, and <code>delta</code> is sensitivity parameter.</p>
</div>
</div>



<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>
